# Local Development

import { Callout } from 'nextra/components';

<Callout type="warning">
	Sui Owned Object Pools (SuiOOP) will likely be replaced by
	[`ParallelTransactionExecutor`](../executors#paralleltransactionexecutor) from
	`@mysten/sui/transactions`

    Sui Owned Object Pools (SuiOOP) is a beta library. Enhancements and changes are likely during
    development.

</Callout>

## Installing the library

If you would like to extend the library by developing on your local machine, first you need to clone
the repository.

```sh
git clone https://github.com/MystenLabs/Sui_Owned_Object_Pools.git
```

Use a package manager to install dependencies from the root of the project.

```sh npm2yarn
npm install
```

## Testing

Tests, apart from checking if your changes break the existing codebase, are also a great way to get
familiar with the library. For each test scenario, there is a small description of the test's
purpose and the library's commands to achieve that.

To be able to run the tests, first you need to:

1. Publish the package in the `move_examples/nft_app/` folder.
1. Have an account to use as an Admin account to create and execute transactions, from coin
   transfers to NFT minting.
1. Have a test user account to use as a receiver of the transactions.

You can run the `./test/initial_setup.sh` script to perform these steps for you, or perform them
manually.

Before proceeding make sure that you are using the `testnet` environment:

```sh
sui client switch --env testnet && sui client envs
```

Also, make sure that your admin account (the account `sui client active-address` identifies) owns
enough SUI. You can get SUI for a test network from the
[Sui faucet](https://docs.sui.io/guides/developer/getting-started/get-coins).

Next, run the setup script:

```sh
cd test && chmod u+x test/initial_setup.sh # give the user the right to execute the setup script
./initial_setup.sh testnet  # create a setup for testnet
```

The script creates a `.test.env` file in the `test/` folder. When the script is complete, you need
to add an `ADMIN_SECRET_KEY` and a `TEST_USER_SECRET` to the `.env`.

The Testnet network is typically used for testing. Switch to Testnet with:
`sui client switch --env testnet`

At the end of the setup, your `.env` should look like the template
[`.test.env.example.`](https://github.com/MystenLabs/coin_management_system/blob/main/test/.env.example):

```ts
# The Admin should also be the publisher of the nft_app smart contract
ADMIN_ADDRESS= ...
ADMIN_SECRET_KEY= ...

# A user address that is used as a receiver of txs. Used for testing.
TEST_USER_ADDRESS= ...
TEST_USER_SECRET= ...

# Used for testing. Get this by publishing the move_examples/nft_app/
NFT_APP_PACKAGE_ID= ...
NFT_APP_ADMIN_CAP= ...

# Example: "https://fullnode.testnet.sui.io:443"
SUI_NODE= ...

GET_WORKER_TIMEOUT_MS=1000
```

<Callout type="default">
	You can run `cat ~/.sui/sui_config/sui.keystore` to see your addresses' secret keys. Each secret's
	corresponding address is in the same row line that appears in `sui client addresses`.
</Callout>

The [jest framework](https://jestjs.io/) is recommended for testing. Having installed the project's
packages with `npm install`, you can run the tests by either:

- [Recommended] The vscode `jest` extension (Extension ID: **Orta.vscode-jest**)

  The extension provides a flask to the IDE sidebar where you run the tests (altogether or
  one-by-one) and shows the results in the editor. You can also run the tests in debug mode and set
  breakpoints in the code. Useful when performing
  [test-driven development](https://en.wikipedia.org/wiki/Test-driven_development).

- [Best for CI/CD] Run `npm run test` from the command line.

## Code consistency

Before committing your changes, run the linter to check for code style consistency.

```sh npm2yarn
npm run lint
```
